home *** CD-ROM | disk | FTP | other *** search
- ;void write_center(strg,col,row,length,ln_color,strg_color);
- ; unsigned char *strg,col,row,length,ln_color,strg_color;
-
- EXTRN _memory_model:byte
- EXTRN _video_buffer:word
- EXTRN _snow_protect:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _write_center
- _write_center proc near
- cld ;direction flag forward
- push bp ;
- mov bp,sp ;set stack frame
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;DS changed for LODSB
- mov bl,_snow_protect ;get _snow_protect before change DS
- mov ax,_video_buffer ;fetch _video_buffer
- mov es,ax ;ES pts to buffer
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov si,[bp+4] ;near case
- L00: sub dx,dx ;DX counts string length
- push si ;keep initial pointer position
- L000: cmp byte ptr[si],0 ;end of string?
- je L0000 ;jump if so
- inc si ;inc ptr
- inc dx ;inc counter
- jmp short L000 ;loop till end
- L0000: pop si ;restore ptr
- sub cx,cx ;
- mov cl,[bp+10] ;line length in CX
- mov [bp+10],bl ;save _snow_protect
- mov byte ptr[bp+11],0 ;_error_code 0 = no error
- sub cx,dx ;line len minus strg len
- cmp cx,0 ;Length greater than len(Strg)?
- jge L1 ;jump if so
- sub cx,cx ;otherwise zero fill chars to write
- mov byte ptr[bp+11],1 ;_error_code 1 = Len(Strg) > Length
- L1: mov bx,cx ;copy in BX
- shr cx,1 ;now one half in CX
- sub bx,cx ;remainder in BX
- push bx ;push remainder for later
- push dx ;push strg len for later
- sub ax,ax ;
- mov al,[bp+6] ;Col in DI
- mov di,ax ;
- mov al,[bp+8] ;Row in AX
- dec ax ;count from 0
- mov dl,160 ;bytes in a row
- mul dl ;multiply times rows
- dec di ;count from 0
- shl di,1 ;doubled for attri bytes
- add di,ax ;now DI pts to cursor pos
- mov ah,[bp+12] ;line attribute in AH
- mov al,32 ;space character
- jcxz L3 ;jump if no chars to write
- L2: call WriteIt ;write space on right
- loop L2 ;go do next
- L3: pop cx ;string length
- jcxz L5 ;jump ahead if null strg
- mov ah,[bp+14] ;string attribute in AH
- L4: lodsb ;get a char from string
- call WriteIt ;write char and attribute
- loop L4 ;go do next character
- L5: pop cx ;number spaces on right
- mov ah,[bp+12] ;line attribute in AH
- mov al,32 ;space character
- jcxz L7 ;jump if no chars to write
- L6: call WriteIt ;go draw space on right
- loop L6 ;go do next
- L7: pop ds ;restore DS and quit
- mov al,[bp+11] ;fetch _error_code
- mov _error_code,al ;set it
- pop si ;
- pop di ;
- pop bp ;
- sti ;reenable interrupts
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _write_center endp
- Writeit PROC ;snowprotection procedure
- push dx ;save DX
- mov dx,es ;get video buffer address
- cmp byte ptr[bp+10],0 ;protect against snow?
- je A3 ;jump ahead if not
- mov dx,3dah ;status byte address
- mov bx,ax ;save char-attri in BX
- A1: in al,dx ;get status byte
- test al,1 ;test bit
- jnz A1 ;loop till 0
- cli ;disable interrupts
- A2: in al,dx ;get status byte
- test al,1 ;test bit
- jz A2 ;loop till 1
- mov ax,bx ;return char-attri to AX
- A3: stosw ;write the char and attri
- pop dx ;restore DX and return
- ret
- Writeit endp
- _TEXT ENDS
- END